package product.nutz;

import java.util.HashMap;
import java.util.Map;

import org.nutz.mvc.adaptor.JsonAdaptor;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

public class Amplify {
	@At("/amplifyApiUrl")
	@Ok("json")
    public Map doMyApiUrl() {
        Map map  = new HashMap();
        map.put("foo", "bar");
        map.put("baz", "qux");
        return map;
    }
	
	@At("/amplifyRestFulApi/foo/bar")
	@Ok("json")
    public Map doMyRESTFulApi() {
        Map map  = new HashMap();
        map.put("foo", "bar");
        map.put("baz", "qux");
        return map;
    }
	
	@At("/amplifyRestFulApi")
	@Ok("json")
	@POST
    public Map doMyAjaxPost() {
        Map map  = new HashMap();
        map.put("foo", "bar");
        map.put("baz", "qux");
        return map;
    }
	
	@At("/amplifyDataMaps")
	@Ok("json")
	@AdaptBy(type=JsonAdaptor.class)
    public Map doDataMaps(@Param("q")String q) {	
		out("q="+q);
        Map map  = new HashMap();
        map.put("q",q);
        return map;
    }
	
	@At("/amplifySuccssState")
	@Ok("json")
    public Map doSuccssState() {
        Map map  = new HashMap();
        map.put("status","success");
        Map data = new HashMap();
        	data.put("foo", "bar");
        	data.put("baz", "qux");
        map.put("data", data);	
        return map;
    }
	
	@At("/amplifyFailState")
	@Ok("json")
    public Map doFailState() {
        Map map  = new HashMap();
        map.put("status","fail");
        map.put("message", "failure message.");
        return map;
    }
	
	private void out(Object obj){
		System.out.println(obj);
	}
	
}
